package month_03.day23;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Demo9 {
    int num=0;
    public synchronized void add(){
        num++;
        log.info(".num:"+num);
    }
    public static class T extends Thread{
        private Demo9 demo9;
        public T(Demo9 demo9) {
            this.demo9 = demo9;
        }
        @Override
        public void run() {
            for (int i = 0; i < 1000; i++) {
                this.demo9.add();
                log.info("进程名:"+this.getName());
            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Demo9 demo2 = new Demo9();
        T t1 = new T(demo2);
        T t2 = new T(demo2);
        T t3 = new T(demo2);
        T t4 = new T(demo2);
        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t1.join();
        t2.join();
        t3.join();
        t4.join();
        System.out.println(demo2.num);
    }
}
